<?php

require('functions/pageLoad.php');

// jobs

$query = "SELECT jobs.id, trade, area FROM jobs 
	LEFT JOIN trades ON jobs.trade_id = trades.id 
	LEFT JOIN areas ON jobs.area_id = areas.id 
	WHERE job_active = 1 ORDER BY date_added";
$result = mysql_query( $query ) or die ("Error in query: $query. " . mysql_error());

while($job_rs=mysql_fetch_assoc($result)){

$jobs.='
   <url>
      <loc>http://www.iwantatradesman.co.uk'.build_job_link($job_rs['trade'],$job_rs['area'],$job_rs['id']).'</loc>
      <changefreq>daily</changefreq>
      <priority>0.9</priority>
   </url>';

}

// tradesmen

$query = "SELECT id, username, company_name FROM tradesman WHERE active = 1";
$result = mysql_query( $query ) or die ("Error in query: $query. " . mysql_error());

while($tradesmen_rs=mysql_fetch_assoc($result)){

$tradesmen.='
   <url>
      <loc>http://www.iwantatradesman.co.uk'.build_tradesman_link($tradesmen_rs['company_name'], $tradesmen_rs['id']).'</loc>
      <changefreq>daily</changefreq>
      <priority>0.9</priority>
   </url>';

}

// tradesman landing pages

	// get all areas
	
	$areas = array();
	$areas[0] = 'all-areas';
	/*
	$query = "SELECT url FROM areas ORDER BY area";
	$result = mysql_query( $query ) or die ("Error in query: $query. " . mysql_error());

	while($area_rs=mysql_fetch_assoc($result)){
		$areas[] = $area_rs['url'];
	}
	*/
	// loop through trades
	
	$query = "SELECT url FROM trades ORDER BY trade";
	$result = mysql_query( $query ) or die ("Error in query: $query. " . mysql_error());

	while($trade_rs=mysql_fetch_assoc($result)){
	
	
		foreach($areas AS $area){
		
		$landing.='
		   <url>
			  <loc>http://www.iwantatradesman.co.uk/tradesmen/'.$trade_rs['url'].'/'.$area.'</loc>
			  <changefreq>daily</changefreq>
			  <priority>0.9</priority>
		   </url>';
		
		}
	
	}	

$header='<?xml version="1.0" encoding="UTF-8" ?>';

header ("content-type: text/xml");
echo $header."\r\n"

?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>http://www.iwantatradesman.co.uk/</loc>
      <changefreq>daily</changefreq>
      <priority>1</priority>
   </url>
   <url>
      <loc>http://www.iwantatradesman.co.uk/how-it-works</loc>
      <changefreq>monthly</changefreq>
      <priority>0.9</priority>
   </url>
   <url>
      <loc>http://www.iwantatradesman.co.uk/register</loc>
      <changefreq>monthly</changefreq>
      <priority>0.9</priority>
   </url>
   <url>
      <loc>http://www.iwantatradesman.co.uk/help</loc>
      <changefreq>weekly</changefreq>
      <priority>0.9</priority>
   </url>
   <url>
      <loc>http://www.iwantatradesman.co.uk/register-my-business</loc>
      <changefreq>weekly</changefreq>
      <priority>0.9</priority>
   </url>
   <url>
      <loc>http://www.iwantatradesman.co.uk/tradesmen</loc>
      <changefreq>daily</changefreq>
      <priority>0.9</priority>
   </url>
<?php echo $landing; ?>
<?php echo $tradesmen; ?>
   <url>
      <loc>http://www.iwantatradesman.co.uk/contact-us</loc>
      <changefreq>monthly</changefreq>
      <priority>0.5</priority>
   </url>
   <url>
      <loc>http://www.iwantatradesman.co.uk/terms</loc>
      <changefreq>yearly</changefreq>
      <priority>0.1</priority>
   </url>
   <url>
      <loc>http://www.iwantatradesman.co.uk/privacy</loc>
      <changefreq>yearly</changefreq>
      <priority>0.1</priority>
   </url>
   <url>
      <loc>http://www.iwantatradesman.co.uk/links</loc>
      <changefreq>daily</changefreq>
      <priority>1</priority>
   </url>
   <url>
      <loc>http://www.iwantatradesman.co.uk/link-exchange</loc>
      <changefreq>monthly</changefreq>
      <priority>1</priority>
   </url>
   <url>
      <loc>http://www.iwantatradesman.co.uk/refer-a-friend</loc>
      <changefreq>monthly</changefreq>
      <priority>1</priority>
   </url>
<?php echo $jobs; ?>
</urlset>